Links und Funktionen
Sprachumschaltung

Navigationspfad
Sie sind hier: Startseite / Probestudium / 2015 / WS I: 3D-Programmierung / Skripte / wie man die Maus abfragt (4) drag and drop.py


Inhaltsbereich

wie man die Maus abfragt (4) drag and drop.py

Python Source icon wie man die Maus abfragt (4) drag and drop.py — Python Source, 1 KB

Dateiinhalt

from visual import *

scene.range = 5

kugel = sphere(pos=(-3,0,0), color=color.cyan)
wuerfel = box(pos=(+3,0,0), size=(2,2,2), color=color.red)
pick = None #das angeklickte Objekt - am Anfang keines

while True:
    rate(30)
    if scene.mouse.events:
        m1 = scene.mouse.getevent() # get event
        if m1.drag and m1.pick == kugel: # if touched
            drag_pos = m1.pickpos # where on the ball
            pick = m1.pick # pick now true (not None)
        elif m1.drop: # released at end of drag
            pick = None # end dragging (None is false)
    if pick:
        # project onto xy plane, even if scene rotated:
        new_pos = scene.mouse.project(normal=(0,0,1))
        if new_pos != drag_pos: # if mouse has moved
            # offset for where the ball was touched:
            pick.pos += new_pos - drag_pos
            drag_pos = new_pos # update drag position

Funktionsleiste